package com.wjm.blog.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wjm.blog.common.base.response.Result;
import com.wjm.blog.system.service.ISysUserService;
import com.wjm.blog.system.vo.request.SysUserQueryVo;
import com.wjm.blog.system.vo.request.SysUserSaveVo;
import com.wjm.blog.system.vo.response.SysUserDetailVo;
import com.wjm.blog.system.vo.response.SysUserListVo;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 用户信息表Controller
 *
 * @author wjm
 * @version 1.0
 * @date 2023-10-18T14:34:39.366
 */
@Log4j2
@Api(tags = "用户信息表管理")
@RestController
@RequestMapping("/api/v1.0")
public class SysUserController {
    @Autowired
    private ISysUserService sysUserService;

    @ApiOperation(value = "用户信息表分页查询接口", notes = "用户信息表分页查询接口")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )
    @GetMapping("/sysUsers/page")
    Result<IPage<SysUserListVo>> page(@ModelAttribute SysUserQueryVo queryVo) throws Exception {
        return Result.success(sysUserService.page(queryVo));
    }

    @ApiOperation(value = "用户信息表列表查询接口", notes = "用户信息表列表查询接口")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )
    @GetMapping("/sysUsers")
    Result<List<SysUserListVo>> list(@ModelAttribute SysUserQueryVo queryVo) throws Exception {
        return Result.success(sysUserService.list(queryVo));
    }

    @ApiOperation(value = "用户信息表详情查询接口", notes = "用户信息表详情查询接口")
    @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )
    @GetMapping("/sysUsers/{id}")
    Result<SysUserDetailVo> get(@PathVariable Long id) throws Exception {
        return Result.success(sysUserService.get(id));
    }

    @ApiOperation(value = "用户信息表新增接口", notes = "用户信息表新增接口")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )
    @PostMapping("/sysUser")
    Result insert(@RequestBody @Valid SysUserSaveVo saveVo) throws Exception {
        return Result.success(sysUserService.insert(saveVo));
    }

    @ApiOperation(value = "用户信息表修改接口", notes = "用户信息表修改接口")
    @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )
    @PutMapping("/sysUser/{id}")
    Result update(@PathVariable Long id, @RequestBody @Valid SysUserSaveVo saveVo) throws Exception {
        return Result.success(sysUserService.update(id, saveVo));
    }

    @ApiOperation(value = "用户信息表作废(批量)接口", notes = "用户信息表作废(批量)接口")
    @ApiImplicitParam(name = "ids", value = "主键ID数组，多个ID以英文逗号分隔", dataType = "Array")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )
    @PutMapping("/sysUsers/invalid")
    Result remove(@RequestParam List<Long> ids) throws Exception {
        return Result.success(sysUserService.invalid(ids));
    }
}